package com.dwxt.cdms.controller;

import com.dwxt.cdms.base.Page;
import com.dwxt.cdms.entity.HealthParameter;
import com.dwxt.cdms.service.HealthService;
import com.dwxt.common.base.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/cdms/health")
public class HealthController {

    @Autowired
    private HealthService healthService;

    /**
     * 查询公共健康参数列表
     * @return
     */
    @RequestMapping("/selectHealthParameter")
    public BaseResult selectHealthParameter(){
        return healthService.selectHealthParameter();
    }

    /**
     * 查询客户私人健康参数列表
     * @param customerId
     * @return
     */
    @RequestMapping("/selectCustomerHealthParameter")
    public BaseResult selectCustomerHealthParameter(String customerId){
        return healthService.selectCustomerHealthParameter(customerId);
    }

    /**
     * 新增或修改参数列表
     * @param healthParameterList
     * @return
     */
    @RequestMapping("/insertOrUpdate")
    public BaseResult insertOrUpdate(@RequestBody HealthParameter[] healthParameterList){
        return healthService.insertOrUpdate(healthParameterList);
    }

    /**
     * 修改参数列表
     * @param healthParameter
     * @return
     */
    @RequestMapping("/updateHealthParameter")
    public BaseResult updateHealthParameter(HealthParameter healthParameter){
        return healthService.updateHealthParameter(healthParameter);
    }

    /**
     * 查询健康预警记录分页
     * @param name
     * @param community
     * @param page
     * @param orderBy
     * @param isHandle
     * @return
     */
    @RequestMapping("/selectHealthRecordPage")
    public BaseResult selectHealthRecordPage(String name, String community, Page page,
                                             String orderBy, Integer isHandle, String category,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                             @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date endTime,
                                             Integer stationId){
        return healthService.selectHealthRecordPage(name,community,page,orderBy,isHandle,category,startTime,endTime,stationId);
    }

    /**
     * 处理健康预警
     * @param id
     * @param isHandle
     * @return
     */
    @RequestMapping("/handle")
    public BaseResult handle(Integer id,Integer isHandle){
        return healthService.handle(id,isHandle);
    }


    /**
     * 用户及报警数量--看板
     * @return
     */
    @GetMapping("/selectCountFromHealthRecord")
    public BaseResult selectCountFromHealthRecord(Integer stationId){
        return healthService.selectCount(stationId);
    }

    /**
     * 数据看板
     * @return
     */
    @GetMapping("/selectAllDataCount")
    public BaseResult selectAllDataCount(Integer stationId){
        return healthService.selectAllDataCount(stationId);
    }



    /*@RequestMapping("/selectAllWarnPage")
    public BaseResult selectAllWarnPage(Page page,String customerId,Integer isHandle){
        return healthService.selectAllWarnPage(page,customerId,isHandle);
    }*/

    /**
    * @Description: 数据面板报警列表
    * @Param [stationId, page, isHandle]
    * @Return com.dwxt.common.base.BaseResult
    * @Author chendq
    * @Date 2022/1/10
    **/
    @RequestMapping("/selectBackAllWarnPage")
    public BaseResult selectBackAllWarnPage(Integer stationId, Page page,Integer isHandle){
        return healthService.selectBackAllWarnPage(page,stationId,isHandle);
    }

    /**
     *查询 HealthRecord,warn的并集  每两个小时的数量
     * @return
     */
    @RequestMapping("/selectAllWarnGraphHour")
    public BaseResult selectAllWarnGraphHour(){
        return healthService.selectAllWarnGraphHour();
    }

    /**
     *查询 HealthRecord,warn的并集  每个月的数量
     * @return
     */
    @RequestMapping("/selectAllWarnGraphMonth")
    public BaseResult selectAllWarnGraphMonth(){
        return healthService.selectAllWarnGraphMonth();
    }

    /**
     * 查询 HealthRecord,warn的并集  未处理事件的数量
     * @return
     */
    @RequestMapping("/countNotHandleWarn")
    public BaseResult countNotHandleWarn(){
        return healthService.countNotHandleWarn();
    }

    /**
    * @Description: 通过客户id或者手机查询最新的10条报警信息
    * @Param [customerId,phone]
    * @Return com.dwxt.common.base.BaseResult
    * @Author chendq
    * @Date 2021/12/19
    **/
    @GetMapping("/selectWarnByCutomerIdOrPhone")
    public BaseResult selectWarnByCutomerIdOrPhone(Integer customerId,String phone){
        return healthService.selectWarnByCutomerIdOrPhone(customerId,phone);
    }


    /**
     * 社区查询接口
     * @return
     */
    @GetMapping("/selectCountForCommunity")
    public BaseResult selectCountForCommunity(){
        return healthService.selectCountForCommunity();
    }
}
